package cn.yunyichina.reservation.controller.business;

import cn.yunyichina.provider.framework.dubbo.service.ReservationService;
import cn.yunyichina.provider.iface.entity.common.Response;
import cn.yunyichina.reservation.common.ResponseEnum;
import cn.yunyichina.reservation.common.jackson.Jackson;
import cn.yunyichina.reservation.constant.HttpResponse;
import cn.yunyichina.reservation.controller.BaseController;
import cn.yunyichina.reservation.controller.console.ConsoleLoginController;
import cn.yunyichina.reservation.vo.MechanismVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * Created by JoeZ on 2016/8/24.
 */
@RestController
@RequestMapping("mechanism")
public class MechanismController extends BaseController{

    private static final Logger logger = LoggerFactory.getLogger(ConsoleLoginController.class);

    /* 获取子系统服务 */
    private static final String RESERVATION_CONSOLE_MECHANISM_LIST = "yyt.reservation.mechanism.list";

    @RequestMapping("list")
    public HttpResponse list(HttpServletRequest request, HttpServletResponse response) {
        HttpResponse httpResponse = new HttpResponse();
        Map<String, Object> map = new HashMap<>();
        String pageNum = request.getParameter("pageNum");
        String pageSize = request.getParameter("pageSize");

        //获取索引参数
        String name = request.getParameter("name");
        String provinceCode = request.getParameter("provinceCode");
        String cityCode = request.getParameter("cityCode");

        map.put("pageNum", pageNum);
        map.put("pageSize", pageSize);
        map.put("cityCode",cityCode);
        map.put("provinceCode",provinceCode);
        map.put("name",name);

        Response serviceResponse = ReservationService.callHumpFromInternal(RESERVATION_CONSOLE_MECHANISM_LIST, Jackson.getBaseJsonData(map));
        if("0".equals(serviceResponse.getResultCode())){
            List<MechanismVo> datas = Jackson.getBeanJsonData(serviceResponse.getResult(), List.class);
            httpResponse.setData(datas);

        }else{
            httpResponse.failure(
                    ResponseEnum.ILLEGAL_PARAMETER.getCode(),
                    ResponseEnum.ILLEGAL_PARAMETER.getMessage());
        }
        return httpResponse.success(ResponseEnum.SUCCESS.getMessage());
    }

}
